<template>
  <div class="app-container" v-loading="pageLoading">
    <el-button type="primary" class="fr" @click="createItem" v-permission="'uph.add'">创建</el-button>
    <div class="filter-container">
      <el-input style="width: 300px" placeholder="输入查询关键字按回车" clearable prefix-icon="el-icon-search" class="filter-item"
        @keyup.enter.native="research" @clear="research" v-model="query.queryString"></el-input>
      <el-button class="filter-item" type="success" plain @click="research">查询</el-button>
      <el-button class="filter-item" type="info" plain @click="exportData" :loading="exportLoading">导出 </el-button>
    </div>
    <z-table :list="list" :tableProps="tableProps" :columns="columns" @editItem="editItem" @deleteItem="deleteItem">
    </z-table>
    <z-pagination :pagination="pagination" :total="total" :page.sync="query.page" :limit.sync="query.size"
      @change="getList"></z-pagination>
    <z-form-dialog :name="name" :data="data" :formProps="formProps" :fields="fields" @submit="submit"
      :submitLoading="submitLoading" :visible.sync="editFormVisible"></z-form-dialog>
  </div>
</template>

<script>
import commonMixin from '@/views/_common/mixin'
export default {
  mixins: [commonMixin],
  name: 'uph',
  data: function () {
    return {
      api: this.$api.uph,
      apiCreate: this.$api.uph + 'update',
      name: '人均产出目标维护',
      columns: [
        { title: '产品编码', key: 'sku_code', width: 130 },
        { title: '产品名称', key: 'sku_name', width: 220 },
        { title: '工序', key: 'group_name', width: 130 },
        { title: 'UPH', key: 'uph', width: 100 },
        { title: 'UPPH', key: 'upph', width: 100 },
        { title: '备注', key: 'remarks' },
        { title: '修改人', key: 'modify_user', width: 100 },
        { title: '最后修改', key: 'modify_time', width: 140 },
      ],
      fields: [
        {
          title: '产品编码',
          key: 'sku_id',
          name: 'select',
          options: [],
          required: true,
          props: {
            filterable: true,
            remote: true,
            remoteMethod: null,
          },
        },
        {
          title: '工序',
          key: 'group_id',
          name: 'select',
          required: true,
          options: [],
          props: {
            filterable: true,
          },
        },
        { title: 'UPH', key: 'uph', name: 'number' },
        { title: 'UPPH', key: 'upph', name: 'number' },
        { title: '备注', key: 'remarks' },
      ],
    }
  },
  methods: {
    formatAfterGet(data) {
      //依据实际需求处理
      this.getSingelSkuOption(data.sku_id)
      return data
    },
    getSkuOption(str) {
      this.$request(this.$api.sku + 'getlist', { queryString: str, page: 1, size: 999 }).then((r) => {
        this.setFieldOptions('sku_id', r.list, 'id', ['key_part_no', 'key_part_name'])
      })
    },
    getSingelSkuOption(id) {
      this.$request(this.$api.sku + 'getbyid', { id: id }).then((r) => {
        this.setFieldOptions('sku_id', r, 'id', ['key_part_no', 'key_part_name'])
      })
    },
  },
  created: function () {
    this.getList()
    this.getFieldConfig('sku_id').props.remoteMethod = this.getSkuOption
    this.$request(this.$api.group + 'getlistbypage', { mes_flag: 'Y' }).then((r) => {
      this.setFieldOptions('group_id', r.list, 'id', 'group_name')
    })
  },
}
</script>
<style scoped>
</style>
